<?php
namespace lib\protocol;
class QQPC{
    protected $url = [];
    protected $host = '';
    protected $api = '';
    public function __construct($api = null){
        $this->api ='https://auth.daoh.top';
        $this->url = [
            $this->api .'/api/pcgetqrcode',
            $this->api .'/api/Getqq',
            $this->api .'/api/Getcookie'
        ];
        $this->host =  $_SERVER['HTTP_HOST'];
    }
    public function Get_QrLogin($type , $qq){
        if ($type !== 'qqpay') return false;
        $return = [];
        $data = [
            'url'=>$this->host,
            'qq'=>$qq
        ];
        $res = get_curl($this->url[0],$data);
        $json = json_decode($res, true);
        if($json['code'] == 1){
            $return = [
                'qr_url'=>$json['qr_url'],
                'type'=>$type,
                'id'=>$qq
            ];
        }else{
            return $json;
        }
        return $return;
    }
    
    public function GET_JIANCE($type , $qq){
        if ($type !== 'qqpay') return false;
        $return = [];
        $data = [
            'qq'=>$qq
        ];
        $res = get_curl($this->url[1],$data);
        $json = json_decode($res, true);
        $code = $json['code'];
        switch($code){
            case 1:
                $cookie = $this->GET_QQCOOKIE($qq);
                if($cookie['code'] == 1 && !empty($cookie['cookie'])){
                    return ['code'=>0,'msg'=>'success','cookie'=>$cookie['cookie']];
                }
                return ['code'=>8,'msg'=>'success'];
                break;
            default :
                $code = $code == 2 ? 6:$code;
                return ['code'=>$code,'msg'=>$json['msg']];
                break;
        }
        return ['code'=>-1,'msg'=>'未知错误'];
    }
    public function GET_QQCOOKIE($qq){
        $data = [
            'qq'=>$qq,
            'url'=>$this->host
        ];
        
        $res = get_curl($this->url[2],$data);
        $json = json_decode($res, true);
        return $json;
    }
}

?>